package com.testvideo.command.mplayer;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class MPlayerCommand {
	protected InputStreamReader sdi ;
	protected OutputStreamWriter sdo ;

	protected boolean isPaused = true ;
	
	public final String COMMAND_SET_PROPERTY = "set_property" ;
	public final String COMMAND_GET_PROPERTY = "get_property" ;
	
	private String br = "\n" ;
	
	public MPlayerCommand(InputStreamReader sdi, OutputStreamWriter sdo){
		this.sdi = sdi ;
		this.sdo = sdo ;
	}	
	
	protected void executeCommandIgnorePausingProblem(String command, String... params){
		String mc = command ;
		if(params != null && params.length > 0){
			for(int i = 0 ; i < params.length ; i++){
				mc += " " + params[i] ;
			}
		}		
		
		try {
			sdo.write(mc + br) ;
			sdo.flush() ;
		} catch (IOException e) {
			e.printStackTrace();
		} finally{
			//do nothing. IO stream is not controlled here.
		}
	}
	
	protected void executeCommandKeepPausing(String command, String... params){
		String mc = command ;
		if(params != null && params.length > 0){
			for(int i = 0 ; i < params.length ; i++){
				mc += " " + params[i] ;
			}
		}
				
		try {
			sdo.write("pausing_keep " + mc + br) ;
			sdo.flush() ;			
		} catch (IOException e) {
			e.printStackTrace();
		} finally{
			//do nothing. IO stream is not controlled here.
		}
	}

}
